package com.ahways.system.service.impl;

import com.ahways.system.entity.Menu;
import com.ahways.system.mapper.MenuMapper;
import com.ahways.system.service.MuneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MenuServiceImpl implements MuneService {
    @Autowired
    public MenuMapper menuMapper;
    @Override
    public List<Menu> getMenu() {
        //待添加结构处理
        List<Menu> query = menuMapper.query();
        List<Menu> list = new ArrayList<>();
        dealMenu(query,list);
        return list;
    }

    public static void dealMenu(List<Menu> list ,List<Menu> newList){
        for (Menu menu:list){
            String code = menu.getCode();
            List<Menu> child = list.stream().filter((m) -> m.getParentCode().equals(code)).collect(Collectors.toList());
            if(child.size()>0){
                menu.setList(child);
            }
            newList.add(menu);
        }
    }

}
